<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        table tr th,td{
            border: 1px solid black;
            text-align: center;
        }
        table{
            border: 1px;
            cell-padding:0;
            cell-spacing:0;
            width: 80%;
            margin-top: 20px;
        }
        table thead{
            background-color:#b3d7ff ;
        }
        a{
            cursor: pointer;
        }

    </style>
    <link rel="stylesheet" href="../css/pintuer.css">
    <link rel="stylesheet" href="../css/bootstrap.css">

    <script src="../js/jquery-3.4.1.min.js"></script>
    <script src="../js/popper.min.js"></script>
    <script src="../js/bootstrap-table1.15.3.js"></script>
    <script src="../js/bootstrap-table-zh-CN.min.js"></script>
    <script src="../js/bootstrap-min-4.3.1.js"></script>
    <script src="../js/pintuer.js"></script>
    <script src="../js/initMain.js"></script>
    <script type="text/javascript">
        function initTable(){
            $("#tableInfo").bootstrapTable({
                method:"post",
                contentType:"application/json",
                url:"/mDesignProcedure/queryMDesignProcedureHasDesign.action",
                //设置交替行样式
                striped:true,
                //初始显示页数
                pageNum:1,
                //是否显示分页
                pagination:true,
                //设置是服务端分页还是客户端分页
                sidePagination:"server",
                //页大小
                pageSize:3,
                //分页列表
                pageList: [3,5,6,10],
                //上传到服务器的参数
                queryParams:function (data) {
                    return{
                        //计算页号，当前号
                        pageNum:(data.offset/data.limit)+1,
                        //计算页大小
                        pageSize: data.limit,
                    }
                },
                columns:[
                    {title:"设计单编号",field:"designId",align:"center",formatter:function (value,row,index) {
                        return "<a href='#' onclick='queryMDesignProcedure("+JSON.stringify(row)+")'>"+value+"</a>"
                    }},
                    {title:"产品编号",field:"productId",align:"center"},
                    {title:"产品名称",field:"productName",align:"center"},
                    {title:"审核状态",field:"moduleCheckTag",align:"center",formatter:function(value,row,index){
                            if(value=='S001-2'){
                                var span='<span style="color: red">审核不通过</span>';
                                return span;
                            }else if(value=='S001-1'){
                                var span='<span style="color: green">审核通过</span>';
                                return span;
                            }else if(value=='S001-0'){
                                var span='<span style="color: black">等待审核</span>';
                                return span;
                            }

                        }}
                ]

            })
        }
        var mDesignProcedureDetailId;
        var mDesignProcedureDetail;
        $(function () {

            initTable();
//点击设计按钮
            $(document).on("click",".designModule",function () {
                mDesignProcedureDetail=$(this);
                mDesignProcedureDetailId=$(this).attr("id");
                $.ajax({
                    url: "/mDesignProcedureDetails/queryAndUpdateMDesignProcedureDetailsById1.action",
                    data: "mDesignProcedureDetailId=" + mDesignProcedureDetailId + "&mDesignProcedureId=" + mDesignProcedure.id + "&productId=" + mDesignProcedure.productId,
                    type: "post",
                    success: function (data) {

                        $("#addDesignModel").modal("show");
                        $("#procedureId").text(data.procedureId);
                        $("#procedureName").text(data.procedureName);
                        $("#register").text(mDesignProcedure.register);
                        $("#designId1").text(mDesignProcedure.designId);
                        $("#registerTime").text(mDesignProcedure.registerTime);


                        $.ajax({
                            url:"/mDesignProcedureModule/queryMDesignProcedureModuleByPId.action",
                            data:"pId="+mDesignProcedureDetailId,
                            type:"post",
                            success:function (data) {
                                // alert(data);
                                $("#dModuleDetailsTBody").empty();

                                var moduleTotal=0;
                                for(var i=0;i<data.length;i++){
                                    var mDesignProcedureModule=data[i];


                                    var trnew=$("<tr>");
                                    var td=$("<td>");
                                    td.html(mDesignProcedureModule.detailsNumber);
                                    var td1=$("<td>");
                                    td1.text(mDesignProcedureModule.productName);
                                    var td2=$("<td>");
                                    td2.text(mDesignProcedureModule.productId);
                                    var td3=$("<td>");
                                    td3.text(mDesignProcedureModule.amount);
                                    var td4=$("<td>");
                                    td4.text(mDesignProcedureModule.amountUnit);
                                    var td5=$("<td>");
                                    td5.text(mDesignProcedureModule.costPrice);
                                    var td6=$("<td>");
                                    td6.text(mDesignProcedureModule.subtotal);


                                    trnew.append(td);
                                    trnew.append(td1);
                                    trnew.append(td2);
                                    trnew.append(td3);
                                    trnew.append(td4);
                                    trnew.append(td5);
                                    trnew.append(td6);

                                    $("#dModuleDetailsTBody").append(trnew);

                                    moduleTotal+=parseFloat(mDesignProcedureModule.subtotal);


                                }
                                $("#moduleSubtotal").text(moduleTotal);
                            }
                        })
                    }
                })

            })


            //点击返回按钮
        $("#cancel").click(function () {
            $("#addDesignModel").modal("hide");
        })

    })
        var mDesignProcedure;
        //点击审核按钮
        function checkModule(obj) {
            $.ajax({
                url:"/mDesignProcedureDetails/queryMDesignProcedureDetailsByPId",
                type:"post",
                data:"pId="+obj.id,
                success:function (data) {
                    mDesignProcedure=obj;
                    mDesignProcedure.id=obj.id;

                    $("#addModel").modal("show");
                    $("#tBody").empty();
                    $("#productId").text(obj.PRODUCT_ID);
                    $("#productName").text(obj.PRODUCT_NAME);
                    //登记人：当前登录用户
                    // alert(localStorage.getItem("userName"));
                    $("#designer").text(obj.designer);
                    $("#designId").text(obj.designId);
                    $("#costPriceSum").text(obj.costPriceSum);
                    $("#moduleChecker").text(localStorage.getItem("userName"));
                    var date=new Date();
                    $("#moduleCheckTime").text(date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+"  "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds());


                    for(var i=0;i<data.length;i++){
                        var mDesignProcedureDetail=data[i];
                        var trnew=$("<tr>");
                        var td=$("<td class='id'>");
                        td.html(mDesignProcedureDetail.id);
                        // count++;
                        var td1=$("<td>");
                        td1.text(mDesignProcedureDetail.procedureName);
                        var td2=$("<td>");
                        td2.text(mDesignProcedureDetail.procedureId);
                        //工时数
                        var td3=$("<td>");
                        if(mDesignProcedureDetail.amountUnit=='hour'){
                            td3.html(mDesignProcedureDetail.labourHourAmount);
                        }else if(mDesignProcedureDetail.amountUnit=='minute'){
                            td3.html(mDesignProcedureDetail.labourHourAmount/60.0);
                        }else if(mDesignProcedureDetail.amountUnit=='day'){
                            td3.html(mDesignProcedureDetail.labourHourAmount*24);
                        }
                        var td4=$("<td>");
                        td4.html(mDesignProcedureDetail.subtotal);

                        var td5=$("<td class='moduleSubtotal'>");

                        // td5.html("<input  style='width: 100px;border: none' class='amountUnit'/>");
                        td5.html(mDesignProcedureDetail.moduleSubtotal);

                        var td6=$("<td>");
                        var a=$("<a>");
                        a.attr("id",mDesignProcedureDetail.id)
                            .attr("class","designModule");
                        a.css("color","#005cbf");
                        // td6.html("<a id='"+mDesignProcedureDetail.id+"' class='designModule' style='color: #005cbf;'></a>");

                        a.text("审核");

                        td6.append(a);


                        trnew.append(td);
                        trnew.append(td1);
                        trnew.append(td2);
                        trnew.append(td3);
                        trnew.append(td4);
                        trnew.append(td5);
                        trnew.append(td6);
                        $("#tBody").append(trnew);


                    }
                    var moduleCostPriceSum=0;
                    for(var i=0;i<$("#tBody tr").length;i++){
                        moduleCostPriceSum+=parseFloat($(".moduleSubtotal").eq(i).text());
                    }
                    $("#moduleCostPriceSum").text(moduleCostPriceSum);

                }
            })
        }

        //点击审核按钮
        function queryMDesignProcedure(obj) {
            $.ajax({
                url:"/mDesignProcedureDetails/queryMDesignProcedureDetailsByPId",
                type:"post",
                data:"pId="+obj.id,
                success:function (data) {
                    mDesignProcedure=obj;
                    mDesignProcedure.id=obj.id;

                    $("#addModel").modal("show");
                    $("#tBody").empty();
                    $("#productId").text(obj.PRODUCT_ID);
                    $("#productName").text(obj.PRODUCT_NAME);
                    //登记人：当前登录用户
                    // alert(localStorage.getItem("userName"));
                    $("#designer").text(obj.designer);
                    $("#designId").text(obj.designId);
                    $("#costPriceSum").text(obj.costPriceSum);
                    $("#moduleChecker").text(obj.moduleChecker);
                    $("#moduleCheckTime").text(obj.moduleCheckTime);
                    $("#moduleCheckSuggestion").text(obj.moduleCheckSuggestion);


                    for(var i=0;i<data.length;i++){
                        var mDesignProcedureDetail=data[i];
                        var trnew=$("<tr>");
                        var td=$("<td class='id'>");
                        td.html(mDesignProcedureDetail.id);
                        // count++;
                        var td1=$("<td>");
                        td1.text(mDesignProcedureDetail.procedureName);
                        var td2=$("<td>");
                        td2.text(mDesignProcedureDetail.procedureId);
                        //工时数
                        var td3=$("<td>");
                        if(mDesignProcedureDetail.amountUnit=='hour'){
                            td3.html(mDesignProcedureDetail.labourHourAmount);
                        }else if(mDesignProcedureDetail.amountUnit=='minute'){
                            td3.html(mDesignProcedureDetail.labourHourAmount/60.0);
                        }else if(mDesignProcedureDetail.amountUnit=='day'){
                            td3.html(mDesignProcedureDetail.labourHourAmount*24);
                        }
                        var td4=$("<td>");
                        td4.html(mDesignProcedureDetail.subtotal);

                        var td5=$("<td class='moduleSubtotal'>");

                        // td5.html("<input  style='width: 100px;border: none' class='amountUnit'/>");
                        td5.html(mDesignProcedureDetail.moduleSubtotal);

                        var td6=$("<td>");
                        var a=$("<a>");
                        a.attr("id",mDesignProcedureDetail.id)
                            .attr("class","designModule");
                        a.css("color","#005cbf");
                        // td6.html("<a id='"+mDesignProcedureDetail.id+"' class='designModule' style='color: #005cbf;'></a>");

                        a.text("查看");

                        td6.append(a);


                        trnew.append(td);
                        trnew.append(td1);
                        trnew.append(td2);
                        trnew.append(td3);
                        trnew.append(td4);
                        trnew.append(td5);
                        trnew.append(td6);
                        $("#tBody").append(trnew);


                    }
                    var moduleCostPriceSum=0;
                    for(var i=0;i<$("#tBody tr").length;i++){
                        moduleCostPriceSum+=parseFloat($(".moduleSubtotal").eq(i).text());
                    }
                    $("#moduleCostPriceSum").text(moduleCostPriceSum);

                }
            })
        }



    </script>
</head>
<body>
    <div>
        <table id="tableInfo">

        </table>
    </div>
    <div class="modal  fade" id="addModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog" style="width: 90%">
            <div class="modal-content" style="border: 1px solid black;">
                <div class="modal-header">
                    <div class="container">
                        <div class="row">
                            <div class="col-7" style="text-align: right">
                                <h5 class="modal-title" id="info" >
                                    工序物料设计单
                                </h5>
                            </div>
                            <div class="col-2"></div>
                            <div class="col-3" style="position: absolute;right: 30px">
                            </div>
                        </div>
                    </div>
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true" style="margin-right: 0px">

                    </button>
                </div>
                <div class="modal-body">
                    <form id="addProcedureForm">
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-2" style="text-align: right">
                                    <span>工序单编号：</span>
                                </div>
                                <div class="col-4">
                                    <span id="designId"></span><br>
                                </div>
                                <div class="col-2" style="text-align: right">
                                    <span>设计人：</span>
                                </div>
                                <div class="col-4">
                                    <span id="designer"></span><br>
                                </div>

                            </div>
                        </div><br>

                        <div class="container">
                            <div class="row">
                                <div class="col-2" style="text-align:right">
                                    产品名称：
                                </div>
                                <div class="col-4">
                                    <span id="productName">笔记本</span>
                                </div>
                                <div class="col-2" style="text-align:right">
                                    产品编号：
                                </div>
                                <div class="col-4">
                                    <span id="productId" >20001002192001</span>
                                </div>
                            </div>
                        </div><br>


                        <table width="800px" style="margin-left: 20px">
                            <thead>
                                <tr>
                                    <th>序号</th>
                                    <th>工序名称</th>
                                    <th>工序编号</th>
                                    <th>工时数(小时)</th>
                                    <th>工时成本小计(元)</th>
                                    <th>物料成本小计(元)</th>
                                    <th>查看</th>
                                </tr>
                            </thead>
                            <tbody id="tBody">

                            </tbody>
                        </table><br>
                        <div class="container">
                            <div class="row">
                                <div class="col-2" style="text-align:right">
                                    工时总成本：
                                </div>
                                <div class="col-4">
                                    <span name="costPriceSum" id="costPriceSum"></span>
                                </div>
                                <div class="col-2" style="text-align:right">
                                    物料总成本：
                                </div>
                                <div class="col-4">
                                    <span id="moduleCostPriceSum">0.00</span>
                                </div>
                            </div>
                        </div><br>
                        <div class="container">
                            <div class="row">
                                <div class="col-2" style="text-align:right">
                                    审核人：
                                </div>
                                <div class="col-4">
                                    <span name="moduleChecker" id="moduleChecker"></span>
                                </div>
                                <div class="col-2" style="text-align:right">
                                    审核时间：
                                </div>
                                <div class="col-4">
                                    <span  name="moduleCheckTime" id="moduleCheckTime"></span>
                                </div>
                            </div>
                        </div><br>
                        <span style="margin-left: 55px">审核意见：</span>
                        <span  id="moduleCheckSuggestion">

                        </span>

                    </form>
                </div>

            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>


<!--    设计工序物料-->
    <div class="modal  fade" id="addDesignModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog" style="width: 90%;height: 500px">
            <div class="modal-content" style="border: 1px solid black;">
                <div class="modal-header">
                    <button class="btn btn-primary" id="cancel" style="position: absolute;right: 90px;">返回</button>
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true" style="margin-right: 0px">

                    </button>
                </div>
                <div style="width: 80%;height: 400px;border: 2px solid gray;margin: 0 auto;margin-top: 10px">
                    <h3 align="center" style="margin-top: 30px">工序物料设计单</h3>
                    <div class="container-fluid">
                        <form id="putRegister">
                            <div class="row" style="margin-top: 30px;">
                                <div class="col-3" style="text-align:right">
                                    设计单编号：
                                </div>
                                <div class="col-4">
                                    <span id="designId1"></span>
                                </div>
                                <div class="col-2" style="text-align:right">
                                    工序名称：
                                </div>
                                <div class="col-3">
                                    <span id="procedureName"></span>
                                </div>

                            </div>
                            <div class="row" style="margin-top: 30px;">
                                <div class="col-3" style="text-align:right">
                                    登记人：
                                </div>
                                <div class="col-4">
                                    <span id="register"></span>
                                </div>
                                <div class="col-2" style="text-align:right">
                                    登记时间：
                                </div>
                                <div class="col-3">
                                    <span id="registerTime"></span>
                                </div>

                            </div>


                            <div>
                                <table width="80%" style="margin-top: 20px;" class="table table-sm">
                                    <thead id="tHead" style="background-color: #b3d7ff;">
                                    <tr >
                                        <th>序号</th>
                                        <th>物料名称</th>
                                        <th>物料编号</th>
                                        <th>本工序数量</th>
                                        <th>单位</th>
                                        <th>单价(元)</th>
                                        <th>小计(元)</th>

                                    </tr>
                                    </thead>
                                    <tbody id="dModuleDetailsTBody">

                                    </tbody>
                                </table>
                            </div>
                            <div class="row" style="margin-top: 30px;">
                                <div class="col-3" style="text-align:right">
                                    物料总成本：
                                </div>
                                <div class="col-4">
                                    <span id="moduleSubtotal"></span>
                                </div>

                            </div>

                        </form>
                    </div>
                </div>

            </div>
        </div>
    </div>
</body>

</html>